cmake_minimum_required(VERSION 3.12)
project(realtime_voice_server CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 使用pkg-config查找sherpa-onnx
find_package(PkgConfig REQUIRED)
pkg_check_modules(SHERPA_ONNX REQUIRED sherpa-onnx)

find_package(Threads REQUIRED)

find_package(OpenSSL REQUIRED)

# 使用FetchContent自动下载依赖
include(FetchContent)

FetchContent_Declare(
    websocketpp
    GIT_REPOSITORY https://github.com/zaphoyd/websocketpp.git
    GIT_TAG 0.8.2
)

FetchContent_Declare(
    cpp-httplib
    GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git
    GIT_TAG v0.15.3
)

FetchContent_Declare(
    nlohmann_json
    GIT_REPOSITORY https://github.com/nlohmann/json.git
    GIT_TAG v3.11.3
)

FetchContent_MakeAvailable(websocketpp cpp-httplib nlohmann_json)

add_executable(server_cpp src/main.cpp)

target_include_directories(server_cpp PRIVATE
    ${websocketpp_SOURCE_DIR}
    ${cpp-httplib_SOURCE_DIR}
    ${nlohmann_json_SOURCE_DIR}/include
    ${SHERPA_ONNX_INCLUDE_DIRS}
)

target_link_directories(server_cpp PRIVATE ${SHERPA_ONNX_LIBRARY_DIRS})

# 链接sherpa-onnx和其他所需库
target_link_libraries(server_cpp PRIVATE
    ${SHERPA_ONNX_LIBRARIES}
    Threads::Threads
    OpenSSL::SSL
    OpenSSL::Crypto
)

# 添加编译标志
target_compile_options(server_cpp PRIVATE ${SHERPA_ONNX_CFLAGS_OTHER})